#include "NetworkReplyAdaptor.h"

#include "private/qhttpnetworkreply_p.h"
#include "private/qhttpthreaddelegate_p.h"
#include "QConnectionObjectEx.h"


class QHttpThreadDelegatePublic : public QHttpThreadDelegate
{
public:
	QHttpNetworkReply* getHttpReply() { return httpReply; }
};



NetworkReplyAdaptor::NetworkReplyAdaptor(QHttpNetworkReply* parent)
	: QObject(parent), replyPrivate((QHttpNetworkReplyPrivate*)((QConnectionObjectEx*) parent)->dFunc()),
	  threadDelegate((QHttpThreadDelegatePublic*) parent->parent())
{
	connect(this, SIGNAL(readyRead()), threadDelegate, SLOT(readyReadSlot()));
}

void NetworkReplyAdaptor::readyReadSlot()
{
	if (replyPrivate->statusCode != 401 && replyPrivate->statusCode != 407 && //replyPrivate->shouldEmitSignals()
			threadDelegate->getHttpReply() != 0)
	{
		emit readyRead();
	}
}

